import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(name = "ServletRequestParams", urlPatterns = "/ServletRequestParams")
public class ServletRequestParams extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println("用户名：" + name);
        System.out.println("密码：" + password);

        String[] hobbys = req.getParameterValues("hobby");
        System.out.print("爱好：");
        for (int i = 0; i < hobbys.length; i++) {
            System.out.println(hobbys[i] + ", ");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
